import {Component, OnInit} from '@angular/core';
import {ListConShareManageComponent} from '../list-con-share-manage.component';
import {Zero3Option} from '../../../../../frame/enum/zero3-option';
import {ConShareManageCondition} from '../../con-share-manage.type';
import {Zero3Enum} from '../../../../../frame/enum/zero3-enum';
import * as fa from '@fortawesome/free-solid-svg-icons';

@Component({
    selector: 'app-search-list-con-share-manage',
    templateUrl: './search-list-con-share-manage.component.html',
    styleUrls: ['./search-list-con-share-manage.component.css']
})
export class SearchListConShareManageComponent implements OnInit {

    // func = this.upper.func;

    zero3Option = Zero3Option;

    condition = new ConShareManageCondition();

    extend = {
        keyup: (event) => {
            // T-O-D-O 51 # err
            if (event.keyCode > 32 || event.keyCode === 8) {
                this.listConShareManage.func.list.click(event);
            }
        },
        condition: {
            creator: {
                icon: fa.faUserAlt,
                nickname: '创建者',
                value: () => {
                    return this.condition.creator;
                },
                keyup: (event) => {
                    this.condition.creator = event.target.value;
                    this.extend.keyup(event);
                }
            },
            serShareName: {
                nickname: '名称',
                value: () => {
                    return this.condition.serShareName;
                },
                keyup: (event) => {
                    this.condition.serShareName = event.target.value;
                    this.extend.keyup(event);
                }
            },
            serTitle: {
                nickname: '分享标题',
                value: () => {
                    return this.condition.serTitle;
                },
                keyup: (event) => {
                    this.condition.serTitle = event.target.value;
                    this.extend.keyup(event);
                }
            },
            serShareType: {
                nickname: '分享类型',
                items: [],
                initItems: () => {
                    this.extend.condition.serShareType.items = [];
                    Zero3Enum.SHARE_FLAG.forEach((val, key) => {
                        this.extend.condition.serShareType.items.push({
                                name: val,
                                id: key,
                            }
                        );
                    });
                },
            }
        },
    };

    constructor(public listConShareManage: ListConShareManageComponent) {
        listConShareManage.search = this;
    }

    ngOnInit() {
        this.extend.condition.serShareType.initItems();
    }

}
